
//
//  ShopCartSectionHeader.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/8/17.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "ShopCartSectionHeader.h"

@interface ShopCartSectionHeader ()
@property(nonatomic,strong)UIImageView * arrowImage;
@end

@implementation ShopCartSectionHeader

-(id)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        
        self.backgroundColor = RGBColor(250, 250, 250);
        UIButton * selectedButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:selectedButton];
        self.selectedButton = selectedButton;
        [selectedButton setImage:[UIImage imageNamed:@"shoppingcart_but_n"] forState:UIControlStateNormal];
        [selectedButton setImage:[UIImage imageNamed:@"shoppingcart_but_s"] forState:UIControlStateSelected];
        [selectedButton addTarget:self action:@selector(selectedButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        titleLabel.text = @"善觉堂野生灵芝馆";
        titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIImageView * arrowImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        arrowImage.image = [UIImage imageNamed:@"nav_return"];
        arrowImage.transform = CGAffineTransformRotate(arrowImage.transform, M_PI);
        [self addSubview:arrowImage];
        self.arrowImage = arrowImage;
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.selectedButton.width = self.height * 0.5;
    self.selectedButton.height = self.selectedButton.width;
    self.selectedButton.x = self.height * 0.25;
    self.selectedButton.centerY = self.height * 0.5;

    
    self.titleLabel.size = [self.titleLabel.text sizeInAre:MaxSize font:self.titleLabel.font];
    self.titleLabel.x = self.selectedButton.right + 5;
    self.titleLabel.centerY = self.selectedButton.centerY;
    self.arrowImage.size = CGSizeMake(10, self.titleLabel.height);
    self.arrowImage.x = self.titleLabel.right + 10;
    self.arrowImage.centerY = self.titleLabel.centerY;
}
-(void)selectedButtonClick:(UIButton*)button{
    button.selected = !button.selected;
    /*
    if(button.selected){
        [button setImage:[UIImage imageNamed:@"icon_center"] forState:UIControlStateNormal];
        button.layer.borderWidth = 0;
    }else{
         [button setImage:nil forState:UIControlStateNormal];
        button.layer.borderWidth = 0.5;
    }
     */
    if([self.delegate respondsToSelector:@selector(selectedButtonClickWithButton:Section:)]){
        [self.delegate selectedButtonClickWithButton:button Section:self.section];
    }
}
@end
